package car4u;

public class Implication {
	
	public enum Type{
		LUKASIEWICZ,
		GODL,
		GOUGEN,
		KLEENE_DIENES,
		ZADEH,
		REICHENBACH,
	}
	
	private Type type;
	
	public Implication(Type type) {
		this.type = type;
	}
	
	public double getImplication(double x, double y){
		switch(type){
			case LUKASIEWICZ:
				return getLukasiewicz(x, y);
				
			case GODL:
				return getGodl(x, y);
				
			case GOUGEN:
				return getGougen(x, y);
				
			case KLEENE_DIENES:
				return getKleeneDienes(x, y);
				
			case ZADEH:
				return getZadeh(x, y);
				
			case REICHENBACH:
				return getReichenbach(x, y);
		}
		return 0;
	}
	
	private double getLukasiewicz(double x, double y) {
		return Math.min(1-x+y, 1);
	}
	
	private double getGodl(double x, double y) {
		if(x <= y){
			return 1;
		}
		else {
			return y;
		}
	}
	
	private double getGougen(double x, double y) {
		if(x == 0){
			return 1;
		}
		else {
			return Math.min(1, y/x);
		}
	}
	
	private double getKleeneDienes(double x, double y) {
		return Math.max(1-x, y);
	}
	
	private double getZadeh(double x, double y) {
		return Math.max(1-x, Math.min(x, y));
	}
	
	private double getReichenbach(double x, double y) {
		return 1-x+x*y;
	}
}
